package com.java110.mall.shop.smo.impl;


import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import com.java110.dto.shop.ShopGoodsDto;
import com.java110.intf.shop.IShopGoodsInnerServiceSMO;
import com.java110.po.shop.ShopGoodsPo;
import com.java110.mall.shop.dao.IShopGoodsServiceDao;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 小区店铺商品内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class ShopGoodsInnerServiceSMOImpl extends BaseServiceSMO implements IShopGoodsInnerServiceSMO {

    @Autowired
    private IShopGoodsServiceDao shopGoodsServiceDaoImpl;


    @Override
    public int saveShopGoods(@RequestBody ShopGoodsPo shopGoodsPo) {
        int saveFlag = 1;
        shopGoodsServiceDaoImpl.saveShopGoodsInfo(BeanConvertUtil.beanCovertMap(shopGoodsPo));
        return saveFlag;
    }

     @Override
    public int updateShopGoods(@RequestBody  ShopGoodsPo shopGoodsPo) {
        int saveFlag = 1;
         shopGoodsServiceDaoImpl.updateShopGoodsInfo(BeanConvertUtil.beanCovertMap(shopGoodsPo));
        return saveFlag;
    }

     @Override
    public int deleteShopGoods(@RequestBody  ShopGoodsPo shopGoodsPo) {
        int saveFlag = 1;
        shopGoodsPo.setStatusCd("1");
        shopGoodsServiceDaoImpl.updateShopGoodsInfo(BeanConvertUtil.beanCovertMap(shopGoodsPo));
        return saveFlag;
    }

    @Override
    public List<ShopGoodsDto> queryShopGoodss(@RequestBody  ShopGoodsDto shopGoodsDto) {

        //校验是否传了 分页信息

        int page = shopGoodsDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            shopGoodsDto.setPage((page - 1) * shopGoodsDto.getRow());
        }

        List<ShopGoodsDto> shopGoodss = BeanConvertUtil.covertBeanList(shopGoodsServiceDaoImpl.getShopGoodsInfo(BeanConvertUtil.beanCovertMap(shopGoodsDto)), ShopGoodsDto.class);

        return shopGoodss;
    }


    @Override
    public int queryShopGoodssCount(@RequestBody ShopGoodsDto shopGoodsDto) {
        return shopGoodsServiceDaoImpl.queryShopGoodssCount(BeanConvertUtil.beanCovertMap(shopGoodsDto));    }

    public IShopGoodsServiceDao getShopGoodsServiceDaoImpl() {
        return shopGoodsServiceDaoImpl;
    }

    public void setShopGoodsServiceDaoImpl(IShopGoodsServiceDao shopGoodsServiceDaoImpl) {
        this.shopGoodsServiceDaoImpl = shopGoodsServiceDaoImpl;
    }
}
